class Solution {
    public List<List<String>> groupAnagrams(String[] strs) {
        Map<String, List<String>> map = new HashMap<>();
        for(String str : strs){
            char[] c = str.toCharArray();
            Arrays.sort(c);
            String s = new String(c);
            List<String> list = map.getOrDefault(s, new ArrayList<String>());
            list.add(str);
            map.put(s, list);
        }
        List<List<String>> ans = new ArrayList<>();
        for(List<String> l : map.values()){
            ans.add(l);
        }
        return ans;
    }
}